package com.ruoyi.system.xmlAbstract.interfaces.paramInterfaces.impl;


import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.system.xmlAbstract.XmlGenerateAbstract;
import com.ruoyi.system.xmlAbstract.interfaces.paramInterfaces.XmlAutoFillParamInterface;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * @author : anxinr
 * @date : 2023/1/30 10:47
 */
@Component(value = "XmlFillParamFromMap")
public class XmlFillParamFromMap implements XmlAutoFillParamInterface {
    @Override
    public boolean fillParam(XmlGenerateAbstract xmlBuild, Object data) {
        try {
            if (ObjectUtil.isEmpty(data)){
                throw new Exception("填充参数不能为空！") ;
            }
            /**数据转换为  HashMap */
            HashMap fillHashMapData = JSON.parseObject(JSON.toJSONString(data), HashMap.class);
            defaultFillParam(xmlBuild.rootXmlNode,fillHashMapData);
            return true ;
        }catch (Exception e){
            return false;
        }
    }
}
